page.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { CashbackTypes } from "@/api/cashback";
  2. import { UserVipInfo } from "@/api/user";
  3. import Box from "@/components/Box";
  4. import { vipImages } from "@/utils/constant";
  5. import { flatPoint, percentage } from "@/utils/methods";
  6. import { server } from "@/utils/server";
  7. import { getTranslations } from "next-intl/server";
  8. import Image from "next/image";
  9. import CashbackTable from "./CashbackTable";
  10. import Progress from "./components/Progress";
  11. import Week from "./Week";
  12. const getVipInfoApi = async () => {
  13. return server
  14. .request<UserVipInfo>({
  15. url: "/v1/api/user/user_vip_info",
  16. method: "post",
  17. })
  18. .then((res) => {
  19. if (res.code === 200) return res.data;
  20. return {
  21. vip_exp: 0,
  22. vip_level: 0,
  23. vip_next_level: 0,
  24. vip_score_exp: 0,
  25. };
  26. });
  27. };
  28. const getCashBackApi = async (): Promise<CashbackTypes> => {
  29. return server
  30. .request<CashbackTypes>({
  31. url: "/v1/api/front/activity_cash",
  32. method: "post",
  33. })
  34. .then((res) => {
  35. return res.data;
  36. })
  37. .catch((error) => {
  38. return {
  39. rules: [],
  40. last_period: { end_time: 0, start_time: 0 },
  41. next_period: {
  42. end_time: 0,
  43. start_time: 0,
  44. },
  45. amount: 0,
  46. bet: 0,
  47. status: "expired",
  48. max_amount: 0,
  49. } as CashbackTypes;
  50. });
  51. };
  52. const CashbackInfo = async () => {
  53. const vipInfo = await getVipInfoApi();
  54. const cashbackInfo = await getCashBackApi();
  55. const currentGrade = cashbackInfo.rules?.find(
  56. (item) => item.level === (vipInfo.vip_level || 1)
  57. );
  58. const maxGrade = cashbackInfo.rules?.at(-1);
  59. const t = await getTranslations();
  60. const vipIconElement = vipImages.map((item, index) => {
  61. if (item.leve === vipInfo.vip_level) {
  62. return (
  63. <div key={index} className={"relative mr-[10px]"}>
  64. <Image src={item.src} alt={"vip"} height={80} width={80} />
  65. <span
  66. className={"absolute bottom-[25%] w-[100%] text-center text-[0.16rem]"}
  67. style={{ color: item.color }}
  68. >
  69. {item.leve}
  70. </span>
  71. </div>
  72. );
  73. }
  74. });
  75. return (
  76. <>
  77. <Box
  78. className={
  79. "w-full mb-[.1rem] rounded-[10px] bg-gradient-to-r from-[#1e2931] to-[#172f29]"
  80. }
  81. >
  82. <div className={"flex"}>
  83. {vipIconElement}
  84. <div className={"flex-1"}>
  85. <div className={"flex items-baseline"}>
  86. <span
  87. className={"mr-[0.06rem] text-[0.23rem] font-bold text-[#11de68]"}
  88. >
  89. {currentGrade?.cashback}%
  90. </span>
  91. <span
  92. className={"mr-[0.06rem] text-[0.23rem] font-bold text-[#11de68]"}
  93. >
  94. {t("cashback.cashbackTitle")}
  95. </span>
  96. <span
  97. className={
  98. "w-[100%] text-right align-text-bottom text-[0.1rem] text-[#fff]"
  99. }
  100. >
  101. Max {maxGrade?.cashback}%
  102. </span>
  103. </div>
  104. <div className={"mt-[0.1rem]"}>
  105. <Progress
  106. num={percentage(vipInfo?.vip_exp, vipInfo.vip_score_exp)}
  107. style={{
  108. "--fill-color": "#11de68",
  109. "--track-color": "#8f9498",
  110. "--track-width": "0.06rem",
  111. }}
  112. />
  113. <div
  114. className={
  115. "font-lightl mt-[0.04rem] text-right text-[0.1rem] text-[#5f7880]"
  116. }
  117. >
  118. {t("ProfilePage.expTips", {
  119. exp: flatPoint(vipInfo.vip_score_exp - vipInfo.vip_exp),
  120. })}
  121. VIP{vipInfo.vip_next_level}
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </Box>
  127. <Week cashbackInfo={cashbackInfo} />
  128. <CashbackTable cashbackInfo={cashbackInfo} />
  129. <div className={"mt-[0.2rem]"}>
  130. <h1 className={"font-bold text-[#fff]"}>{t("cashback.rules")}</h1>
  131. <ul
  132. className={
  133. "list-decimal pl-[0.1389rem] text-[0.12rem] leading-[0.18rem] text-[#6e848b]"
  134. }
  135. >
  136. <li>{t("cashback.rulesFirst")} </li>
  137. <li>{t("cashback.rulesSecond")}</li>
  138. <li>{t("cashback.rulesThird")}</li>
  139. <li>{t("cashback.rulesFourth")}</li>
  140. <li>{t("cashback.rulesFifth")}</li>
  141. <li>{t("cashback.rulesSixth", { max: cashbackInfo.max_amount ?? 0 })}</li>
  142. <li>{t("cashback.rulesSeventh")}</li>
  143. </ul>
  144. </div>
  145. </>
  146. );
  147. };
  148. export default CashbackInfo;